﻿using Microsoft.EntityFrameworkCore;

namespace EFGetStarted
{
    internal class Program
    {
        static void Main(string[] args)
        {
            var id = "5";
            DMContext dc = new DMContext();
            var entity = dc.flowManages.Where(x => x.id == id).AsNoTracking()?.FirstOrDefault(); //.Adapt<BW_WorkFlowManage>();

            if (entity == null)
            {
            }
            else
            {
                entity.name = "复装申请";
                entity.remark = null;
                entity.workflowcode = "fzapply3453";
                entity.workflowname = "复装申请";

            }

            using (var dbTrans = dc.Database.BeginTransaction())
            {
                try
                {
                    // _flowManage.Update(entity,true);
                    dc.flowManages.Update(entity);
                    dc.SaveChanges();
                    dbTrans.Commit();
                }
                catch (Exception ex)
                {
                    //dbTrans.Rollback();
                }
            }

        }
        static void Main1(string[] args)
        {
            Console.WriteLine("Hello, World!");

            DMContext dc = new DMContext();

         //   dc.Database.EnsureCreated();

            using (var dbTrans = dc.Database.BeginTransaction())
            {
                try
                {
                    var check = new BW_CheckVerificat
                    {
                        id = Guid.NewGuid().ToString(),
                        sendcode = "dlkasfjsdlkafjlkasdlk",
                        receivecode = "dlkasfjsdlkafjlkasdlkddddfddfddd",
                        checkstatus = 2,
                        checkresult = 2,
                        brandcode = "01",
                        brandname = "01",
                        calibercode = "01",
                        calibername = "01",
                        modelcode = "01".ToString(),
                        modelname = "01",
                        senddept = "",
                        checktype = "",
                        measure = "",
                        remark = "",
                        whousecode = "01",
                        whousename = "01",
                        floatingstatus = 2,
                        operateuserid = "01",
                        operateusername = "01",
                        checktime = null,
                        addtime = DateTime.Now
                    };
                    var metercode = "402508050";
                    var entity = dc.meterInfos.Where(x => x.metercode == metercode).AsNoTracking()?.FirstOrDefault() ;
                    if (entity != null)
                    {
                        //entity.yccode = "402508050123456789123456789123456789";

                       // entity.id = "492ee7f56c6f4c8dbbfb9a6720a5a9af";
                        entity.metercode="402508050";
                        //"life_status":33,"stock_status":0,"out_projectcode":"","projectcode":"","send_whousecode":"","send_whousename":"",
                        //"receive_whousecode":"10000","receive_whousename":"朔州市城市管理局","remark":"bw修改表信息，备注：","operate_userid":"bw",
                        //"operate_username":"bw","addtime":"2025-08-12 16:16:25"
                        dc.meterInfos.Update(entity);
                    }
                    else
                    {
                        entity = new BW_MeterInfo();
                        entity.id = Guid.NewGuid().ToString();
                        entity.metercode = metercode;
                        entity.stampcode = metercode;
                        entity.factorycode = metercode;
                        entity.yccode = "202510000312202";
                        entity.whousecode = "52501030204";
                        entity.whousename = "仙桃仓库";
                        entity.brandcode = "6";
                        entity.brandname = "新天";
                        entity.calibercode = "MM050";
                        entity.calibername = "DN50";
                        entity.modelcode = "322";
                        entity.modelname = "物联网水表";
                        entity.typecode = "3";
                        entity.typename = "远传表";
                        entity.rangecode = "8";
                        entity.rangename = "999999999";
                        entity.usestatus = 0;
                        entity.stockstatus = 1;
                        entity.repairstatus = 0;
                        entity.origin = "库存录入";
                        entity.intime = DateTime.Now;
                        entity.modifytime = DateTime.Now;
                        entity.addtime = DateTime.Now;
                        entity.modelcode2 = "00";
                        entity.modelname2 = "新天";
                        entity.firstchecktime = DateTime.Now;
                         
                        dc.meterInfos.Add(entity); 

                        
                    }

                    dc.SaveChanges();
                    dbTrans.Commit();
                }catch(Exception ex)
                {
                    dbTrans.Rollback();

                }
            }
               
            /*
            dc.Posts.Add(new Post
            {
                Blog = blog,
                Content = "hhhdh",
                Title = "Title",
            });
            */
          
           
        }
       
    }
}
